package com.bestcem.xm.om.dao.impl;

import com.bestcem.xm.common.core.uitls.DateUtil;
import com.bestcem.xm.om.dao.OmUserPackDao;
import com.bestcem.xm.om.dao.mapper.OmUserPackMapper;
import com.bestcem.xm.om.entity.UserPack;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/15 15:12
 */
@Repository
public class OmUserPackDaoImpl implements OmUserPackDao {
    @Resource
    private OmUserPackMapper omUserPackMapper;

    @Override
    public UserPack getById(String id) {
        return omUserPackMapper.queryById(id);
    }

    @Override
    public List<UserPack> query(UserPack userPack) {
        return omUserPackMapper.query(userPack);
    }

    @Override
    public long count(UserPack userPack) {
        return omUserPackMapper.count(userPack);
    }

    @Override
    public List<UserPack> queryAllByLimit(UserPack userPack, PageRequest pageRequest) {
        return omUserPackMapper.queryAllByLimit(userPack, pageRequest);
    }

    @Override
    public void insert(UserPack userPack) {
        userPack.setCreateTime(DateUtil.getCurrentTime());
        userPack.setUpdateTime(DateUtil.getCurrentTime());
        omUserPackMapper.insert(userPack);
    }

    @Override
    public int deleteById(String id) {
        return omUserPackMapper.deleteById(id);
    }

    @Override
    public void update(UserPack userPack) {
        userPack.setUpdateTime(DateUtil.getCurrentTime());
        omUserPackMapper.update(userPack);
    }
    @Override
    public void updateByPackName(UserPack userPack) {
        userPack.setUpdateTime(LocalDateTime.now());
        omUserPackMapper.updateByPackName(userPack);
    }

    @Override
    public List<UserPack> queryAllPack() {
        return omUserPackMapper.queryAllPack();
    }

    @Override
    public List<UserPack> findByType(Integer type) {
        return omUserPackMapper.findByType(type);
    }

    /**
     * 根据套餐类型查询套餐列表
     *
     * @param type
     * @return
     */
    @Override
    public UserPack findOneByType(Integer type) {
        List<UserPack> packs = omUserPackMapper.findByType(type);
        if(!CollectionUtils.isEmpty(packs)){
            return packs.get(0);
        }
        return null;
    }

    @Override
    public List<UserPack> listByIds(Collection<String> packIds) {
        return omUserPackMapper.listByIds(packIds);
    }

    @Override
    public List<UserPack> listByType(List<Integer> typeList) {
        return omUserPackMapper.listByType(typeList);
    }

    /**
     * 根据名称查询套餐
     *
     * @param name
     * @return
     */
    @Override
    public UserPack getByName(String name) {
        return omUserPackMapper.getByName(name);
    }

    /**
     * 根据套餐名称和类型获取套餐
     *
     * @param name
     * @param type
     * @return
     */
    @Override
    public UserPack getByNameAndType(String name, Integer type) {
        return omUserPackMapper.getByNameAndType(name,type);
    }

    /**
     * 根据类型查询
     *
     * @param type
     * @return
     */
    @Override
    public UserPack getByType(Integer type) {
        return omUserPackMapper.getByType(type);
    }

    @Override
    public List<UserPack> listPackBriefInfo() {
        return omUserPackMapper.listPackBriefInfo();
    }
}
